/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ssdd.chaski.net;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.HashMap;
import java.util.Scanner;
import javax.swing.JComponent;
import javax.swing.JOptionPane;

/**
 *
 * @author jheorge
 */
public class Servidor extends Thread {

    private JComponent ventana;
    private int puerto;
    private Date date;
    ServerSocket svd = null;
    private int i = 0;

    public Servidor() {
        super();
        try {
            puerto = 4444;
            date = new Date();
            svd = new ServerSocket(puerto);
            System.out.println("Servidor arriba el :"
                    + "fecha:" + date.getDay() + "/"
                    + date.getMonth() + "/"
                    + date.getYear() + "/"
                    + date.getHours() + ":"
                    + date.getMinutes() + ":"
                    + date.getSeconds() + "\n");
            start();
        } catch (Exception e) {
            System.out.println("error al iniciar el servidor");
        }

    }

    @Override
    public void run() {
        try {

            while (true) {
                Socket s = svd.accept();
                System.out.println("Bienvenido cliente numero:" + i++);
                GestorConexiones.getInstance().conectarNuevo("NEW", new Conexion(s));
                GestorConexiones.getInstance().tamanioLista();
            }


        } catch (Exception e) {
            JOptionPane.showMessageDialog(ventana, "error al logar la conexion");
        }

    }
}
